if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetActiveQuestionnaireVersionByVersionIdInUse]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetActiveQuestionnaireVersionByVersionIdInUse]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

/***************************************************************************
* Name:			GetActiveQuestionnaireVersionByVersionIdInUse
* Purpose:		Get the active Questionnaire version

* PARAMETERS
* Name				Description					
* -------------		-----------------------------------------------------------
*@versionIdInUse	Questionnaire Version Id in use

***************************************************************************/

CREATE PROCEDURE [dbo].[GetActiveQuestionnaireVersionByVersionIdInUse] (
			@versionIdInUse INT
)
AS
BEGIN

	SET NOCOUNT ON
	
	SELECT		qv.[Id],
		        qv.Version, 
			qv.Active,
			qv.Description,
			qv.QuestionnaireId,
			qv.Published
			FROM QuestionnaireVersion qv
			WHERE qv.Active = 1 
				AND QV.QuestionnaireId = (Select QuestionnaireId from QuestionnaireVersion where id=@versionIdInUse)

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


